package nmea2000

type NMEAHeader struct {
	pgn  uint32
	prio uint32
	src  uint32
	dst  uint32
}

func GetPGN(canID uint32) (NMEAHeader, error) {
	header := NMEAHeader{}

	PF := (canID >> 16) & 0xFF
	PS := (canID >> 8) & 0xFF
	DP := (canID >> 24) & 1

	header.src = canID >> 0
	header.prio = (canID >> 26) & 0x07

	if PF < 240 {
		header.dst = PS
		header.pgn = (DP << 16) + (PF << 8)
	} else {
		header.dst = 0xFF
		header.pgn = (DP << 16) + (PF << 8) + PS
	}
	return header, nil
}
